<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function New(fn) {
        let res = {};
        //绑定原型
        if (fn.prototype != null) {
          res.__proto__ = fn.prototype;
        }
        let ret = fn.apply(res, Array.prototype.slice.call(arguments, 1));
        console.log(ret, "=====ret");
        if (
          (typeof ret == "Object" || typeof ret == "function") &&
          ret != null
        ) {
          return ret;
        }
        console.log(res, "====");
        return res;
      }
      function Person(name, age) {
        this.name = name;
        this.age = age;
      }
      const p1 = New(Person, "uzi", "18");
      console.log(p1.name);
    </script>
  </body>
</html>
